package yxy.game.pm2.command.camptower;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.CampTowerMessage;
import yxy.game.pm2.module.camptower.CampTowerModule;

import java.util.List;

/**
 * 星星领奖页面
 *
 * @ClassName CMD_CampTowerStarTargetUI
 * @Author jingtao-zheng
 * @Date 2022/8/8 10:42
 * @Version 1.0
 **/
@MessageType(proto = Command.CampTowerStarTargetUI, classtype = CampTowerMessage.CampTowerStarTargetUIRequest.class)
public class CMD_CampTowerStarTargetUI extends Command<CampTowerMessage.CampTowerStarTargetUIRequest> {
    @Override
    public void execute(MessageSource messageSource, CampTowerMessage.CampTowerStarTargetUIRequest request) throws Exception {
        String playerCode = messageSource.getTag();
        //获取阵营塔类型
        int type = request.getType().getNumber();
        CampTowerMessage.CampTowerStarTargetUIResponse.Builder response = CampTowerMessage.CampTowerStarTargetUIResponse.newBuilder();
        CampTowerModule towerModule = CampTowerModule.get(playerCode);
        List<Integer> starReward = towerModule.getStarReward().get(type);
        //返回已领取的奖励
        for (Integer starRewardId : starReward) {
            response.addBox(starRewardId);
        }

        send(messageSource, response, Result.Success);
    }

    private void send(MessageSource messageSource, CampTowerMessage.CampTowerStarTargetUIResponse.Builder response, Result result) {
        response.setResult(result.packResult());
        MessageEmitterHandler.getInstance().send(messageSource, response.build());
    }
}
